/*
 * @Author: xiangru.xiao xiangru.xiao@mthreads.com
 * @Date: 2023-05-10 16:38:07
 * @LastEditors: xiangru.xiao xiangru.xiao@mthreads.com
 * @LastEditTime: 2023-05-23 20:11:05
 * Copyright (c) 2023 by Moore Threads, All Rights Reserved. 
 */
#include <string>
#include "objectfactory.h"
#include "node.h"
#include "cu_helper.h"
#include "kernel.cuh"

class GMem_read_bw : public Node
{
public:
    GMem_read_bw()
    {
        nodeUint = "GBPS";
    }
    std::string name() override
    {
        return "gmem-rw-bandwidth";
    }
    std::string describe() override
    {
        return "内存读写带宽";
    }
    Node::NodeType  nodeType() override
    {
        return NodeTP_MemRw;
    }
protected:
    bool startup() override;
    bool perform() override;
    void shutdown() override;
private:
    int        deviceid;
};

bool GMem_read_bw::startup()
{
    deviceid = deviceinfo->deviceID();
    CHECK_CUDA_ERROR(cudaSetDevice(deviceid));
    return true;
}

bool GMem_read_bw::perform()
{
    nodeValue = runMemoryKernel<float4>(deviceinfo);
    return true;
}

void GMem_read_bw::shutdown()
{

}

REGISTER_OBJECT(Node, GMem_read_bw)
